package com.waves.task.strategy.task;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.waves.task.domain.dto.TaskPageDTO;
import com.waves.task.domain.enums.TaskTypeEnum;
import com.waves.task.domain.vo.TaskVO;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 收藏贴策略类
 */
@Component
public class TaskCollectStrategy extends AbstractTaskStrategy {
    @Override
    TaskTypeEnum getTaskTypeEnum() {
        return TaskTypeEnum.TASK_TYPE_COLLECT;
    }

    @Override
    public TaskPageDTO dealTaskPageDTO(TaskPageDTO dto) {
        return null;
    }

    @Override
    public IPage<TaskVO> getTaskVOPage(TaskPageDTO dto) {
        IPage<TaskVO> taskVoPage = super.searchAndDealPage(dto);
        // 当查询个人主页的收藏贴
        List<TaskVO> records = taskVoPage.getRecords();
        // 判断这条帖子当前用户是否收藏 未收藏就移除这条数据
        records.removeIf(record -> !super.isCollected(record.getId(), dto.getUserId()));
        taskVoPage.setRecords(records);
        taskVoPage.setTotal(records.size());
        return taskVoPage;
    }

}
